import pymysql

conn = pymysql.Connect(host='localhost', port=3306, user='root', password='root',
                       database='books', charset='utf8', autocommit=False)

cursor = conn.cursor()

delete_sql = "delete from t_book where title = '西游记';"
cursor.execute(delete_sql)

print('受影响的行：', conn.affected_rows())

# 提交事务，增加、修改、删除都需要
conn.commit()

cursor.close()

conn.close()
